﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetLastNewsList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            LastNewsOutParam result = new LastNewsOutParam();
            LastNewsInParam param = new LastNewsInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            { 
                param = inParam as LastNewsInParam; 

                if(isFlag)
                {
                    DataTable dt = InterfaceHelper.QueryNewsSuoYeImage("D658070EC3BF425BA8417745FDCBFCB0");
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        LastNews itemTemp;
                        string url = CommonUtils.AppAddressEx + "html/InformationDetail.aspx?InfoType={0}&InfoID={1}";
                        foreach (DataRow dr in dt.Rows)
                        {
                            itemTemp = new LastNews();
                            itemTemp.image_url = dr["HomePageImage"].ToString();
                            itemTemp.msg_id = dr["msg_id"].ToString();
                            itemTemp.title = dr["title"].ToString();
                            itemTemp.detail_url = string.Format(url, dr["infoType"], dr["msg_id"]);

                            if (!string.IsNullOrEmpty(itemTemp.image_url))
                                itemTemp.image_url = CommonUtils.AppAddress + SXT.Utility.FileServer.QueryFileUrl(itemTemp.image_url);

                            result.data.list.Add(itemTemp);
                        }
                    } 
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetLastNewsList", SerializeHelper.JsonSerializer<LastNewsInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<LastNewsInParam, LastNewsOutParam>();
            else
                SafeProcessRequest<LastNewsInParam, LastNewsOutParam>();
        }
    }

    #region 请求参数
    public class LastNewsInParam
    {
    }
    #endregion

    #region 结果参数
    public class LastNewsOutParam
    {
        public LastNewsOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new LastNewsList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 列表
        /// </summary>
        public LastNewsList data
        { get; set; }
    }

    public class LastNewsList
    {
        public LastNewsList()
        { 
            list = new List<LastNews>();
        }

        public List<LastNews> list { get; set; } 
    }
     
    /// <summary>
    /// 资讯列表
    /// </summary>
    public class LastNews
    {
        /// <summary>
        ///	资讯ID 
        /// </summary>
        public string msg_id
        { get; set; }
        /// <summary>
        ///	资讯标题 
        /// </summary>
        public string title
        { get; set; }
        /// <summary>
        ///	图片 
        /// </summary>
        public string image_url
        { get; set; }
        /// <summary>
        ///	 
        /// </summary>
        public string detail_url
        { get; set; }
    }
    #endregion 
}